package com.saer.client.window;

import com.saer.client.grid.diagnostico.VisitaGrid;
import com.saer.client.label.TextLabel;
import com.smartgwt.client.types.Alignment;
import com.smartgwt.client.types.VerticalAlignment;
import com.smartgwt.client.widgets.Button;
import com.smartgwt.client.widgets.Window;
import com.smartgwt.client.widgets.events.ClickEvent;
import com.smartgwt.client.widgets.events.ClickHandler;
import com.smartgwt.client.widgets.layout.HLayout;

public class AlertWindow extends Window {

	protected Button openButton = new Button();
	protected Button postponeButton = new Button();
	VisitaGrid visitaGrid = null;

	public AlertWindow(VisitaGrid vVisitaGrid) {

		this.visitaGrid = vVisitaGrid;
		
		setTitle("ALERTA");
		setWidth(325);
		setHeight(195);
		setLayoutAlign(Alignment.CENTER);
		setShowMinimizeButton(false);
		setShowCloseButton(false);
		setIsModal(true);
		setShowModalMask(true);
		centerInPage();

		postponeButton.setWidth(100);
		postponeButton.setHeight(25);
		postponeButton.setTitle("Posponer (1 min)");
		postponeButton.addClickHandler(new ClickHandler() {
			public void onClick(ClickEvent event) {
				visitaGrid.postponeAlert(20);
				destroy();
			}
		});
		
		openButton.setWidth(100);
		openButton.setHeight(25);
		openButton.setTitle("Abrir");
		openButton.addClickHandler(new ClickHandler() {
			public void onClick(ClickEvent event) {
				visitaGrid.openOldestNewVisita(AlertWindow.this);
			}
		});
		
		HLayout buttonsLayout = new HLayout(30);
		buttonsLayout.setAlign(Alignment.CENTER);
		buttonsLayout.setLayoutAlign(VerticalAlignment.CENTER);
		buttonsLayout.setWidth(120);
		buttonsLayout.setHeight(30);
		buttonsLayout.addMember(postponeButton);
		buttonsLayout.addMember(openButton);

		TextLabel textLabel = new TextLabel("<br><h1>Solicitud de Asistencia Remota</h1><br>");
		textLabel.setBackgroundColor("red");
		textLabel.setTextColor("white");
		textLabel.setAlign(Alignment.CENTER);
		textLabel.setBorder("1px solid");
		textLabel.setMargin(2);
		
		addItem(textLabel);
		addItem(buttonsLayout);
		
		show();

	}
	
	@Override
	public void destroy() {
		visitaGrid.setIsShowingAlert(false);
		super.destroy();
	}
	
}
